var express = require('express');
var router = express.Router();
var admin = require('../controls/admin');
var path = require('path');
// multer中间件来处理HTTP请求中的文件上传
var multer = require('multer');
var storage = multer.diskStorage({ //指定上传文件的存储位置和文件名
    destination: (req, file, cb) => { //(请求对象，文件对象，回调函数)
        cb(null, 'public/images');//(未发生错误，文件保存的目标目录)
    },
    filename: (req, file, cb) => { //定义了文件名的生成规则
        let ext = path.extname(file.originalname);//从文件名中提取文件的扩展名
        cb(null, 'myaddgoods' + Date.now() + path.extname(file.originalname));
    }
});
var upload = multer({ storage: storage }); 

router.get('/addgoods', (req, res) => {
    res.render('addgoods', {});
});
router.post('/showgoods', admin.showgoods); //展示所有商品
router.post('/addgoods', upload.single('img'), admin.addgoods); // 新增商品图片  处理前端名为'img'的单文件上传
router.post('/editgoods', upload.single('img'),admin.editgoods);
router.post('/Offshelf',admin.Offshelf);
router.post('/Onshelf', admin.Onshelf);
router.post('/showusers', admin.showusers); //展示所有用户信息
router.post('/showtrueorder', admin.showtrueorder); //展示所有已支付订单信息
router.post('/showfalseorder', admin.showfalseorder); //展示所有未支付订单信息
router.post('/ConfirmShipment', admin.ConfirmShipment); //确认发货
router.post('/yizhifu', admin.yizhifu); //已支付数量
router.post('/weizhifu', admin.weizhifu); //未支付数量
router.post('/userstatistics', admin.userstatistics); //用户数量统计
router.post('/salestatistics', admin.salestatistics); //销售额统计
router.post('/echone', admin.echone); //商城各分类商品数量 echarts
router.post('/echtwo', admin.echtwo); //订单发货数 echarts
router.post('/echthree', admin.echthree); //下单的各分类商品数量 echarts

module.exports = router;

